﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace MyMusicPlay._4._0
{
    public partial class MainWindow : Window
    {
        /// <summary>
        /// 修改歌单配置
        /// </summary>
        public void UpdateDispositionOfMusicLists_Click(object sender, RoutedEventArgs e)
        {
            var curButton = sender as Button;
            var butNameIndex = curButton.Name.Split('_')[1];
            var stackP = Disposition_ListBox.FindName($"DispStackP_{butNameIndex}") as StackPanel;
            var arr = stackP.GetElement<TextBox>();

            Disposition.UpdateDispositionOfMusicList(Convert.ToInt32(butNameIndex), arr[0].Text, arr[1].Text);

            //重新渲染歌单列表
            UpdateMusicList(Convert.ToInt32(butNameIndex), arr[0].Text, arr[1].Text);

        }

        /// <summary>
        /// 修改背景图片
        /// </summary>
        public void UpdateDispositionOfBackImage_Click(object sender, RoutedEventArgs e)
        {
            var stackP = Disposition_ListBox.FindName("TitleImage") as StackPanel;

            var path = stackP.FindName("TitleImageTextBox") as TextBox;

            Disposition.UpdateDispositionOfImage(path.Text);

            UpdateBackImage(path.Text);
        }

        /// <summary>
        /// 修改背景高斯模糊[结束]
        /// </summary>
        public void BackImageEffectSlider_LostMouseCapture(object sender, MouseEventArgs e)
        {
            Disposition.UpdateDispositionOfBackEffect((sender as Slider).Value);
        }

        /// <summary>
        /// 修改背景高斯模糊[实时]
        /// </summary>
        public void BackImageEffectSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateBackEffect(e.NewValue);
        }

        /// <summary>
        /// 修改背景透明度[结束]
        /// </summary>
        public void BackImageOpacitySlider_LostMouseCapture(object sender, MouseEventArgs e)
        {
            Disposition.UpdateDispositionOfBackOpacity((sender as Slider).Value);
        }

        /// <summary>
        /// 修改背景透明度[实时]
        /// </summary>
        public void BackImageOpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateBackgroundOpacity(e.NewValue);
        }

        /// <summary>
        /// 修改背景颜色[结束]
        /// </summary>
        public void BackColorR_LostMouseCapture(object sender, MouseEventArgs e)
        {
            var color = (MainGrid.Background as SolidColorBrush).Color;
            var curColor = (sender as Slider).Value;
            Disposition.UpdateDispositionOfBackColor(new int[] { Convert.ToInt32(curColor), color.G, color.B });
        }
        public void BackColorG_LostMouseCapture(object sender, MouseEventArgs e)
        {
            var color = (MainGrid.Background as SolidColorBrush).Color;
            var curColor = (sender as Slider).Value;
            Disposition.UpdateDispositionOfBackColor(new int[] { color.R, Convert.ToInt32(curColor), color.B });
        }
        public void BackColorB_LostMouseCapture(object sender, MouseEventArgs e)
        {
            var color = (MainGrid.Background as SolidColorBrush).Color;
            var curColor = (sender as Slider).Value;
            Disposition.UpdateDispositionOfBackColor(new int[] { color.R, color.G, Convert.ToInt32(curColor) });
        }
        /// <summary>
        /// 修改背景颜色[实时]
        /// </summary>
        public void BackColorR_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateBackgroundColor(0, Convert.ToInt32(e.NewValue));
        }
        public void BackColorG_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateBackgroundColor(1, Convert.ToInt32(e.NewValue));
        }
        public void BackColorB_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateBackgroundColor(2, Convert.ToInt32(e.NewValue));
        }

        /// <summary>
        /// 修改背景图片
        /// </summary>
        public void UpdateDispositionOfMusicPlayingBoardBackImage_Click(object sender, RoutedEventArgs e)
        {
            var stackP = Disposition_ListBox.FindName("TitleMusicPlayingBoardImage") as StackPanel;
            var path = stackP.Children[0] as TextBox;

            Disposition.UpdateDisposition(u =>
            {
                u.MusicPlayingBoardBackImage.Path = path?.Text;
            });

            UpdateMusicPlayingBoardBackImage(path.Text);
        }

        public void MusicPlayingBoardOpacitySlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            UpdateMusicPlayingBoardOpacity(e.NewValue);
        }

        public void MusicPlayingBoardOpacitySlider_LostMouseCapture(object sender, MouseEventArgs e)
        {
            var opacity = (sender as Slider).Value;
            Disposition.UpdateDisposition(u =>
            {
                u.MusicPlayingBoardBackImage.Opacity = (sender as Slider).Value;
            });
            UpdateMusicPlayingBoardOpacity(opacity);
        }
    }
}
